<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>DataSource</title>
    <link rel="stylesheet" href="js/layui/css/layui.css"/>
    <link rel="stylesheet" href="css/layui-blue.css"/>
    <script type="text/javascript" src="js/layui/layui.all.js"></script>
</head>
<body style="padding:5px;">
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input type="text" name="userPhone" id="userPhone" disabled required lay-verify="" placeholder="" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">原密码</label>
        <div class="layui-input-inline">
            <input type="password" name="userPasswordOld" required lay-verify="required" placeholder="请输入密码"
                   autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">8位数字或字母组合</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" name="userPassword" required lay-verify="required" placeholder="请输入密码" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">8位数字或字母组合</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-inline">
            <input type="password" name="passwordAgain" required lay-verify="required" placeholder="请输入密码"
                   autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">8位数字或字母组合</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">头像</label>
        <div class="layui-input-block">
            <button type="button" class="layui-btn" id="test1">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
        </div>
    </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" type="button" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script type="text/javascript" src="login/js/jquery-2.1.1.min.js"></script>
<link href="js/toastr/toastr.min.css" rel="stylesheet">
<script src="js/toastr/toastr.min.js"></script>
<script type="text/javascript" src="my/mycommon.js"></script>
<script>
    var thisUsers = getThisUser();
    $("#userPhone").val(thisUsers.userPhone);

    //执行实例
    var upload = layui.upload;
    var headerId = this_userInfo.userHeaderId;//返回头像的链接
    var headerUrl = this_userInfo.userHeaderUrl;//返回头像的链接
    var uploadInst = upload.render({
        elem: '#test1' //绑定元素
        , headers: {Authorization: sessionStorage.getItem("userToken")}
        , url: '/common/fileUpload' //上传接口
        , done: function (res) {
            //上传完毕回调
            headerId = res.data.fileId;
            headerUrl = res.data.fileUrl;
        }
        , error: function () {
            //请求异常回调
        }
    });

    layui.use('form', function () {
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function (data) {
            var usersForm = data.field;
            console.log(usersForm);
            if (!usersForm.userPassword || !usersForm.passwordAgain || usersForm.userPassword != usersForm.passwordAgain) {
                toastr.error('密码 和 确认密码不相等！！');
                return false;
            }
            console.log(usersForm.password != usersForm.passwordAgain);
            var users = {};
            users.userPhone = usersForm.userPhone;
            users.userPasswordOld = usersForm.userPasswordOld;
            users.userPassword = usersForm.userPassword;
            users.userHeaderId = headerId;
            users.userHeaderUrl = headerUrl;
            myAjax("/users/update", users, function (result) {
                toastr.success(result.message);
                sessionStorage.setItem('userToken', "Users_" + result.data.userPhone);
                sessionStorage.setItem('userInfo', JSON.stringify(result.data));
                top.location.reload();
            });
            return false;
        });
    });

    //检查是否有权限
    myAjax("/users/updateCheckPer", {}, function (result) {
    });
</script>
</body>
</html>